﻿Imports System.Web.Security '   |||||   Required Class for Authentication
Imports System.Data '   |||||   DB Accessing Import
Imports System.Configuration    '   ||||||  Required for Web.Config appSettings |||||


Imports System
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Xml.Linq
Imports Exp.Model
Imports Exp.DATA_Service

Public Class Login1
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        '   |||||   Put user code to initialize the page here
    End Sub
    Private Sub cmdSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSubmit.Click
        If Page.IsValid Then
            Dim pss As String = GetDataUtil.getMD5Hash(Me.txtPassword.Text.Trim)


            Dim objUs As New Exp.DATA_Service.User_Service

            Dim objUser = objUs.GetByUserPss(Me.txtUserName.Text.Trim, pss)


            If Not objUser Is Nothing Then
                If objUser.isActive = True Then
                    Session("USER") = objUser
                    objUs.UpdateLogin(objUser.User_ID)

                    Dim key As String = ""

                    Select Case objUser.Role_ID
                        Case 1
                            key = "DefalutPage.Admin"

                        Case 2
                            key = "DefalutPage.Approver"

                        Case 3
                            key = "DefalutPage.Owner"

                    End Select

                    Response.Redirect(ConfigurationManager.AppSettings(key))
                Else
                    lblMessage.Text = "This Account is status inactive."
                End If


            Else
                lblMessage.Text = "Invalid Login!"
            End If

        End If
    End Sub

  
End Class